<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<%@ page import="com.hilaver.dzmis.Constants" %>
<%@ page import="com.hilaver.dzmis.util.*" %>
<%@ page import="com.hilaver.dzmis.service.impl.*" %>
<%@ page import="com.hilaver.dzmis.codetable.*" %>
<%@ page import="com.hilaver.dzmis.product.ProductYarn" %>
<%@ page import="com.hilaver.dzmis.procurement.Procurement" %>
<%@ page import="com.hilaver.dzmis.product.ProductIdentification" %>
<%
	Integer id = Integer.parseInt(request.getParameter("id"));
	CtServiceImpl cs = new CtServiceImpl();
	ProcurementServiceImpl ps = new ProcurementServiceImpl();
	I18nServiceImpl i18n = new I18nServiceImpl();
	BiPantoneColorServiceImpl pcService = new BiPantoneColorServiceImpl();
	Locale locale = (Locale) request.getSession().getAttribute(
			Constants.SESSION_LOCALE);
	ps.setLocale(locale);
	Procurement procurement = ps.getObj(id);
	StockServiceImpl stockService = new StockServiceImpl();
	List<ProductYarn> pyList = ps.getYarn(id);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
<link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
<title><%=procurement.getName() %></title>
</head>
<body>
<% for(int i = 0; i < pyList.size(); i++){ 
	//String[] pantoneColors = ps.getDiffPantoneColorFrom(piList);
	List<ProductIdentification> piList = ps.getPiListFromYarn(procurement, pyList.get(i));
	List<String> customerColorList = ps.getDiffCustomerColor(piList, pyList.get(i));
	ProductYarn py = pyList.get(i);
%>
<table cellspacing="0" id="the-table" style="width: 100%;">
	<tr>
		<td style="background:#eeeeee;" colspan="<%=customerColorList.size() + 3 %>"><b><%=i18n.getShortMessage(locale, "ui.productidentification.yarn") %>:</b>&nbsp;&nbsp;<%=py.getFil() %>&nbsp;&nbsp;<%=py.getBiYarn().getReference() %>&nbsp;&nbsp;<%=cs.getDescription(CtMaterialType.class.getName(), py.getBiYarn().getCtMaterialType(), locale) %></td>
	</tr>
	<!-- Color header -->
	<tr>
		<td width="150"><b><%=i18n.getShortMessage(locale, "ui.reference.reference") %></b></td>
		<td width="100"><b><%=i18n.getShortMessage(locale, "message.edit.collar") %></b></td>
		<%for(int j =0; j < customerColorList.size(); j ++){ %>
			<td><%=customerColorList.get(j)%></td>
		<%} %>
		<td width="150"><b><%=i18n.getShortMessage(locale, "message.list.total") %>(Kg)</b></td>
	</tr>
	<!-- Product Identification row-->
	<%for(int k = 0; k < piList.size(); k ++){
		ProductIdentification pi = piList.get(k);
	%>
	<tr>
		<td><b><%=pi.getReference()%>&nbsp;/&nbsp;<%=pi.getWeight()%>g</b></td>
		<td><b><%=cs.getDescription(CtCollarType.class.getName(), pi.getBiMeasureSpecification().getCtCollarType(), locale)%></b></td>
		<%for(int j =0; j < customerColorList.size(); j ++){ %>
			<td><%=ps.getWeightFromCustomerColor(pi, py, customerColorList.get(j)) %></td>
		<%} %>
		<td width="150" class="x-grid3-td-total"><%=ps.getWeightFromYarn(pi, py) %></td>
	</tr>
	<%}%>
	<tr>
		<td style="text-align: right;" colspan="2"><b><%=i18n.getShortMessage(locale, "message.list.total") %>(Kg)</b></td>
		<%for(int j =0; j < customerColorList.size(); j ++){ %>
			<td class="x-grid3-summary-row"><%=ps.getTotalWeightFromColor(piList, py, customerColorList.get(j)) %>&nbsp;&nbsp;(<%=stockService.getYarnTotalStock(py, customerColorList.get(j))%>)</td>
		<%} %>
		<td width="150" class="x-grid3-total"><%=ps.getTotalWeightFromYarn(piList, py) %></td>
	</tr>
</table>
<br/>
<%} %>
</body>
</html>